/**
 * This file is part of Wireless TransFer.
 *
 *   Wireless TransFer is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *	
 *   Wireless TransFer is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with Wireless TransFer.  If not, see <http://www.gnu.org/licenses/>.
 *
 *	 Copyright (C) 2011
 *   @author skalman
 */

package com.wirelesstransfer.server.ConnectedClients;

import java.io.File;
import java.util.List;

import com.wirelesstransfer.connection.TransferData;

public class ConnectedClient extends TransferData {
		
	private final int SLEEPTIME = 1000 * 120;
	private String Ip;
	private String id;
	private Thread activity;
	private Runnable clientRun;

	/**
	 * @param ip is the clients ip address
	 * @param id is the clients id from the server
	 * @parem list is the list of available files for the cilent
	 */
	public ConnectedClient(String Ip, final String id, List<File> list) {
		super(list);
		this.Ip = Ip;
		this.id = id;
		this.clientRun = new CheckConnectedClient(this, SLEEPTIME);
		this.activity = new Thread(clientRun);
		activity.start();
		
	}
	
	/**
	 * Interrupts current CheckConnectedClient thread
	 * and starts a new one.
	 */
	public synchronized void updateThread(){
		System.err.println("Client " + id + " updating");
		activity.interrupt();
		try {
			activity.join(10);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		activity = new Thread(clientRun);
		activity.start();
	}

	public String getId(){
		return id;
	}
	
	public String getIP() {
		return Ip;
	}

}
